<template>
  <div>
    <basic-container>
      <curd-title :title="'基本信息'" />
      <avue-form ref="form" :option="option" v-model="form">
        <template slot="supplierName">
          <el-input class="pointer" v-model="form.supplierName" @focus="selectSupplier" placeholder="请选择" readonly>
            <i slot="suffix" class="el-icon-search"></i>
          </el-input>
        </template>
        <template slot="purchaseEngineer">
          <leading v-model="form.purchaseEngineer" />
        </template>
      </avue-form>
    </basic-container>
    <basic-container>
      <capa-info ref="info" :info.sync="cc" />
    </basic-container>
  </div>
</template>

<script>
import CurdTitle from '@/components/base/title'
import CapaInfo from '@/views/tenant/supplier/capa/components/info'
import { option, supplierOption } from '@/option/tenant/supplier/capa-form'
import { submit, detail } from '@/api/supplier/capacity'
export default {
  name: 'CapaForm',
  prop: ['type', 'params'],
  components: { CurdTitle, CapaInfo },
  data() {
    return {
      cc: [],
      form: {},
      option: option.call(this)
    }
  },
  mounted() {
    this.type && ['edit', 'view'].includes(this.type) && this.getDetail(this.params.id)
  },
  methods: {
    selectSupplier() {
      this.$quickModal({
        title: '选择供应商',
        width: '80%',
        componentIsTag: true,
        component: 'suppliers',
        props: {
          multiple: false,
          columns: supplierOption
        },
        on: {
          change: row => {
            this.form.supplierId = row.id
            this.form.supplierName = row.supplierName
            this.form.supplierCode = row.supplierCode
            this.form.supplierIdentity_dictText = row.supplierIdentity_dictText
            this.form.supplierIdentity = row.supplierIdentity
            this.form.purchaseEngineer = row.purchaseEngineer
            console.log(row)
          }
        }
      })
    },
    handleSave() {
      this.$refs.info.$refs.crud.$refs.cellForm.validate() &&
        this.$refs.form.validate((vaild, done) => {
          if (vaild) {
            let data = {
              capacityClassifyList: [Object.assign(this.form, ...this.cc)],
              supplierId: this.form.supplierId
            }
            console.log(data)
            submit(data).then(res => {
              console.log(res)
              this.$emit('update:visible', false)
              done()
            })
          }
        })
    },
    async getDetail(id) {
      await detail(id).then(res => {
        console.log(res)
      })
    },
    handleClose() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style></style>
